<?php
include_once "regsettings.php";
// NOTE - session_start() must be called first in calling file

/**
 * Check If the user is logged in.  If not, send to the login page (which also has a link to registraiton)
 * @param string $pagename this should be the filename of the page (php file), as indexed in the users_pages table 
 */
function reg_CheckAccess($pagename, $level = 1, $pathtoreg = REG_DIRECTORY){
	if(($_SESSION['user_is_logged_in']<>1) OR empty($_SESSION['user_id'])) {

	  header("Location: " . $pathtoreg . "login.php?referrer=$pagename");
	  exit();
	}

	if (empty($_SESSION['all'] ) AND empty($_SESSION[$pagename]) ) {
		//print 'Failed second check';
		header("Location: " . $pathtoreg . "login.php?referrer=$pagename&msg=");
		exit();
	}else{
		return ($_SESSION['all'] OR $_SESSION[$pagename]); // Should return one or the other
	}

}
 
 // from php random manual blog
function generateRandStr($length){
      $randstr = "";
      for($i=0; $i<$length; $i++){
         $randnum = mt_rand(0,61);
         if($randnum < 10){
            $randstr .= chr($randnum+48);
         }else if($randnum < 36){
            $randstr .= chr($randnum+55);
         }else{
            $randstr .= chr($randnum+61);
         }
      }
      return $randstr;
   } 

   function regMakeSafe($input){
	return $input;
   }
   
?>
